<?php
/**
 * Created by PhpStorm.
 * User: chenzhitao
 * Date: 2018/4/1
 * Time: 下午3:38
 */

namespace app\index\controller;


use app\index\model\News;
use app\index\model\SubCategory;
use app\index\service\CategoryService;
use app\index\service\ConsultService;
use app\index\service\NewsService;
use app\index\service\UrlService;
use think\Controller;
use think\Request;

class Consult extends BaseController
{
    public function index(){
        $category_list = CategoryService::getSupCategoryList();
        $url_list = UrlService::getIndexThirdUrlList();
        $index_new_list = NewsService::getNewsIndexData();
        $this->assign("category_list",$category_list);
        $this->assign("index_news_list",$index_new_list);
        $this->assign("thirdurl_list",$url_list);
        $this->assign("idIndex","4");

        $this->fetch("public/header");
        $this->fetch("public/footer");
        $year = date('Y')."年";
        $this->assign("year",$year);
        return $this->fetch("inforHome",["idIndex"=>"4"]);
    }
    
    public function constList($id, $page){

		if($id == null){
            $id = 0;
        }
        if($page == null){
            $page = 1;
        }
        if($page != 1){
            $pagetext = '第'.$page.'页';
        }else{
            $pagetext = '';
        }
        $category_list = CategoryService::getSupCategoryList();
        $url_list = UrlService::getIndexThirdUrlList();
        $news_list = NewsService::getNewsList($page);

        $hot_news = NewsService::getHotNewsList();

        $news_category_list = NewsService::getSubCategorysByNews();
        $all_category_list = CategoryService::getAllSubCategoryList();


        $this->assign("category_list",$category_list);
        $this->assign("news_category_list",$news_category_list);
        $this->assign("all_category_list",$all_category_list);
        $this->assign("thirdurl_list",$url_list);
        $this->assign("news_list",$news_list);
        $this->assign("hot_news_list",$hot_news);

        $this->assign("idIndex","4");
        $this->fetch("public/header");
        $subcategory_name = SubCategory::getCategoryNameById($id);
        $year = date('Y')."年";
        $this->assign("year",$year);
        return $this->fetch("inforList", ["id"=>$id,"idIndex"=>"4","subcategory_name"=>$subcategory_name,"page"=>$page,"pagetext"=>$pagetext]);
    }
    
    public function constDetail($id){
		if($id == null){
            $id = 0;
        }
        $category_list = CategoryService::getSupCategoryList();
        $url_list = UrlService::getIndexThirdUrlList();
        $detail_news = NewsService::getNewsDetail($id);
//        if(!$detail_news['detail']){
//            return $this->assign("public/404");
//        }
        $hot_news = NewsService::getHotNewsList();
        $year = date('Y')."年";
        $this->assign("year",$year);
        $this->assign("category_list",$category_list);
        $this->assign("thirdurl_list",$url_list);
        $this->assign("detail_news",$detail_news);
        $this->assign("hot_news_list",$hot_news);
        $seo = News::getSeoInfoByID($id);
        $title = $seo['title'];
        $desc = $seo['desc'];
        return $this->fetch("inforDt", ["id"=>$id,"idIndex"=>"4","title"=>$title,"desc"=>$desc]);
    }
    
}